package com.why.blog.admin.post.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.why.blog.common.R;
import com.why.blog.common.ResponseCode;
import com.why.blog.entity.HaloPost;
import com.why.blog.entity.VO.PostVO;
import com.why.blog.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author TriggerWu
 * @version 1.0.0
 * @ClassName PostApi.java
 * @Description post的api接口
 * @createTime 2019年05月14日 11:12:00
 */
@RestController
@RequestMapping("/api/post")
public class PostApi {
    @Autowired
    private PostService postService;

     /**
      * @Title: 前台记录里返回条状记录条内容
      * @Description: 前台记录里返回条状记录条内容
      * @Param: 
      * @Return: 
      * @Author: TriggerWu
      * @Date: 2019/5/14
      * @Time: 11:14
     **/
    @GetMapping("/showTree")
    public R showPolist(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "limit", defaultValue = "30") Integer pageSize
    ) {
        PostVO postVO = new PostVO();
        IPage<HaloPost> iPage = postService.showList(postVO, page, pageSize);
        if (iPage.getRecords().size() == 0) {
            return R.getInstance(ResponseCode.INFO_NO_MORE.getCode(),ResponseCode.INFO_NO_MORE.getMsg());
        }
        return R.getInstance(ResponseCode.RESPONSE_SUCCESS.getCode(),ResponseCode.RESPONSE_SUCCESS.getMsg(),iPage);
    }

     /**
      * @Title: 查询post的总条数
      * @Description: 查询post的总条数
      * @Param: 
      * @Return: 
      * @Author: TriggerWu
      * @Date: 2019/5/14
      * @Time: 11:29
     **/
    @GetMapping("/count")
    public Integer postRecords(@RequestParam(value = "categoryId" ,required = false)Integer categoryId){
        if(categoryId ==null){
            categoryId = -1;
        }
        return postService.postRecords(categoryId);
    }

}
